import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/project',
  children: [{
    path: 'project',
    name: 'Project',
    component: () => import('@/views/project/index'),
    meta: {
      title: '项目概述',
      icon: 'project'
    }
  }]
},
{
  path: '/gis',
  component: Layout,
  redirect: '/gis',
  children: [{
    path: 'gis',
    name: 'Gis',
    component: () => import('@/views/gis/index'),
    meta: {
      title: 'GIS地图',
      icon: 'GIS'
    }
  }]
},
{
  path: '/dashboardScene',
  component: Layout,
  redirect: '/dashboardScene',
  meta: {
    title: '数据中心',
    icon: 'data'
  },
  children: [
    {
      path: 'chart',
      name: 'Chart',
      component: () => import('@/views/chart/index.vue'),
      meta: {
        title: 'GIS数据',
        icon: 'GIS'
      }
    }, {
      path: 'dashboardScene',
      name: 'DashboardScene',
      component: () => import('@/views/dashboard/index'),
      meta: {
        title: '实时数据',
        icon: 'example'
      },
      hidden: true
    }, {
      path: '3d',
      name: 'three3D',
      component: () => import('@/views/three/3d'),
      meta: {
        title: '三维展示',
        icon: 'scene'
      },
      hidden: true
    }]
},
{
  path: '/totalStation',
  component: Layout,
  redirect: '/totalStation',
  children: [{
    path: 'totalStation',
    name: 'TotalStation',
    component: () => import('@/views/totalStation/index1'),
    meta: {
      title: '全站仪数据',
      icon: 'totalStation'
    }
  }]
},
{
  path: '/deviceChart',
  component: Layout,
  // redirect: '/chart',
  meta: {
    title: '设备图表',
    icon: 'chart'
  },
  children: [{
    path: 'deviceChart',
    name: 'deviceChart',
    component: () => import('@/views/deviceChart'),
    meta: {
      title: '设备图表',
      icon: 'GIS'
    }
  }]
},
//   // children: [{
//   //   path: 'gnssChart',
//   //   name: 'GnssChart',
//   //   component: () => import('@/views/chart/gnssChart/index'),
//   //   meta: { title: 'GNSS数据', icon: 'chart' }
//   // },
//   // {
//   //   path: 'moveChart',
//   //   name: 'MoveChart',
//   //   component: () => import('@/views/chart/moveChart/index'),
//   //   meta: { title: '位移传感器', icon: 'chart' }
//   // },
//   // {
//   //   path: 'laserChart',
//   //   name: 'LaserChart',
//   //   component: () => import('@/views/chart/laserChart/index'),
//   //   meta: { title: '激光传感器', icon: 'chart' }
//   // },
//   // {
//   //   path: 'ultrasonicChart',
//   //   name: 'UltrasonicChart',
//   //   component: () => import('@/views/chart/ultrasonicChart/index'),
//   //   meta: { title: '超声波气象站', icon: 'chart' }
//   // },
//   // {
//   //   path: 'soilChart',
//   //   name: 'SoilChart',
//   //   component: () => import('@/views/chart/soilChart/index'),
//   //   meta: { title: '管式土壤检测', icon: 'chart' }
//   // },
//   // {
//   //   path: 'airChart',
//   //   name: 'AirChart',
//   //   component: () => import('@/views/chart/airChart/index'),
//   //   meta: { title: '室内空气监测', icon: 'chart' }
//   // }]
// },
{
  path: '/warning',
  component: Layout,
  redirect: '/warning',
  // meta: { title: '预警中心', icon: 'GIS' },
  children: [{
    path: 'warning',
    name: 'WarningCenter',
    component: () => import('@/views/warning'),
    meta: {
      title: '预警中心',
      icon: 'warring'
    },
    hidden: false
  },
  {
    path: '/scene/warning',
    name: 'SceneWarning',
    hidden: true,
    component: () => import('@/views/warning/warning/center'),
    meta: {
      title: '设置预警',
      icon: 'scene'
    },
    hidden: true
  }
  ]
},
{
  path: '/deviceOption',
  component: Layout,
  redirect: '/DeviceOption',
  meta: {
    title: '设备管理',
    icon: 'device'
  },
  children: [{
    path: '/device/table',
    name: 'DeviceTable',
    component: () => import('@/views/device/index'),
    meta: {
      title: '设备管理',
      icon: 'equipment'
    },
    hidden: true
  }, {
    path: 'deviceOption',
    name: 'DeviceOption',
    component: () => import('@/views/deviceOption/index'),
    meta: {
      title: '传感器数据',
      icon: 'device'
    }
  }
  ]
},
// {
//   path: '/three',
//   component: Layout,
//   redirect: '/three/3d',
//   // hidden: true,
//   meta: { title: '三维展示', icon: 'scene' },
//   children: [
//     {
//       path: '3d',
//       name: 'three3D',
//       component: () => import('@/views/three/3d'),
//       meta: { title: '三维展示', icon: 'scene' }
//     }
//   ]
// },
// 404 page must be placed at the end !!!
{
  path: '/gnss',
  component: Layout,
  redirect: '/gnss',
  children: [{
    path: 'gnss',
    name: 'GNSS',
    component: () => import('@/views/gnss/index'),
    meta: {
      title: 'GNSS',
      icon: 'GIS'
    }
  }]
},
{
  path: '*',
  redirect: '/404',
  hidden: true
}
]

export const syncRoutes = [
  // {
  //   path: '/scene',
  //   component: Layout,
  //   redirect: '/scene/table',
  //   meta: { title: '场景管理', icon: 'scene' },
  //   children: [
  //     {
  //       path: '/scene/table',
  //       name: 'SceneTable',
  //       component: () => import('@/views/scene/index'),
  //       meta: { title: '场景管理', icon: 'scene' }
  //     },

  //     {
  //       path: '/scene/info/:id(\\d+)',
  //       name: 'SceneInfo',
  //       hidden: true,
  //       component: () => import('@/views/scene/info'),
  //       meta: { title: '场景详情', icon: 'scene' }
  //     }
  //   ]
  // },
  // {
  //   path: '/device',
  //   component: Layout,
  //   redirect: '/device/table',
  //   meta: { title: '设备管理', icon: 'equipment' },
  //   children: [
  //     {
  //       path: '/device/table',
  //       name: 'DeviceTable',
  //       component: () => import('@/views/device/index'),
  //       meta: { title: '设备管理', icon: 'equipment' }
  //     }
  //   ]
  // },
  {
    path: '/issued',
    component: Layout,
    redirect: '/issued/warning',
    meta: {
      title: '系统设置',
      icon: 'system'
    },
    children: [{
      path: '/scene/table',
      name: 'SceneTable',
      component: () => import('@/views/scene/index'),
      meta: {
        title: '场景管理',
        icon: 'scene'
      },
      hidden: true
    }, {
      path: '/issued/user',
      name: 'SceneTable',
      component: () => import('@/views/user/index'),
      meta: {
        title: '用户管理',
        icon: 'user'
      }
    },

    {
      path: '/scene/info/:id(\\d+)',
      name: 'SceneInfo',
      hidden: true,
      component: () => import('@/views/scene/info'),
      meta: {
        title: '场景详情',
        icon: 'scene'
      }
    },

    {
      path: 'index',
      name: 'Issued',
      component: () => import('@/views/issued/index'),
      meta: {
        title: '下发指令',
        icon: 'example'
      },
      hidden: true
    }, {
      path: 'alert',
      name: 'Alert',
      hidden: true,
      component: () => import('@/views/issued/alert'),
      meta: {
        title: '警报范围',
        icon: 'example'
      },
      hidden: true
    },
    // {
    //   path: 'warning',
    //   name: 'WarningCenter',
    //   component: () => import('@/views/issued/warning/center'),
    //   meta: { title: '预警阀值', icon: 'example' }
    // },
    {
      path: 'message',
      name: 'Message',
      component: () => import('@/views/issued/message'),
      meta: {
        title: '推送管理',
        icon: 'example'
      },
      hidden: true
    }, {
      path: 'warnDevice',
      name: 'WarnDevice',
      component: () => import('@/views/issued/warnDevice'),
      meta: {
        title: '报警器管理',
        icon: 'example'
      },
      hidden: true
    },
    {
      path: '/firmware_update/index',
      name: 'Firmware',
      component: () => import('@/views/firmware_update/index'),
      meta: {
        title: '固件升级',
        icon: 'example'
      },
      hidden: true
    }
    ]
  }
  // {
  //   path: '/firmware_update',
  //   component: Layout,
  //   redirect: '/firmware_update/index',
  //   children: [{
  //     path: '/firmware_update/index',
  //     name: 'Firmware',
  //     component: () => import('@/views/firmware_update/index'),
  //     meta: { title: '固件升级', icon: 'example' }
  //   }]
  // }
]
const isAdmin = localStorage.getItem('isAdmin')

let endRoutes = constantRoutes
if (isAdmin === 'true') {
  endRoutes = [...constantRoutes, ...syncRoutes]
}

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: endRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
